package com.ncloud.crm.mapper;

import com.ncloud.crm.entity.BsCloudIpseg;
import com.ncloud.crm.entity.BsPublicCloud;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shiqiang on 2017/4/17.
 */
@Mapper
public interface BsPublicCloudIpsegMapper {
    @Select(value = { "select * from bs_cloud_ipseg where seg_inst_id = #{segInstId} and now() between begin_date and end_date" })
    @Results({ @Result(column = "seg_inst_id", property = "segInstId"), @Result(column = "cloud_id", property = "cloudId"),
            @Result(column = "vpc_ip_seg", property = "vpcIpSeg"),@Result(column="gateway_ip",property="gatewayIp"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
    public BsCloudIpseg getCloudSegByPk(Long segInstId);

    @Insert("insert into bs_cloud_ipseg(seg_inst_id, cloud_id, vpc_ip_seg, gateway_ip, begin_date, end_date, update_time, update_user)"
    		+ " values(#{segInstId}, #{cloudId}, #{vpcIpSeg}, #{gatewayIp}, #{beginDate}, #{endDate}, #{updateTime}, #{updateUser})")
	public int insertCloudSeg(BsCloudIpseg node);

    @Update("update bs_cloud_ipseg set gateway_ip=#{gatewayIp},vpc_ip_seg=#{vpcIpSeg},"
    		+ " end_date=#{endDate},update_time=#{updateTime},update_user=#{updateUser}"
    		+ " where cloud_id=#{cloudId} and seg_inst_id=#{segInstId} and begin_date = #{beginDate}")
	public int updateNodeCloud(BsCloudIpseg bsCloudIpseg);

    @Select(value = { "select * from bs_cloud_ipseg where cloud_id = #{cloudId} and now() between begin_date and end_date" })
    @Results({ @Result(column = "seg_inst_id", property = "segInstId"), @Result(column = "cloud_id", property = "cloudId"),
			@Result(column = "vpc_ip_seg", property = "vpcIpSeg"),@Result(column="gateway_ip",property="gatewayIp"),
			@Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
			@Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser")})
	public List<BsCloudIpseg> getCloudSegByCloudId(Long cloudId);


}
